package com.javabasic.algorithm.leetcode;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/6/11 22:32
 */
public class 强密码检验器II {
    public boolean strongPasswordCheckerII(String password) {
        if (null == password || password.isEmpty()) {
            return false;
        }
        int len = password.length();
        if (len < 8) {
            return false;
        }

        boolean smallChar = false;
        boolean bigChar = false;
        boolean numChar = false;
        boolean specChar = false;
        boolean diffChar = true;

        String specStr = "!@#$%^&*()-+";

//        specChar = password.matches("[!@#$%^&*()-+]");

        for (int i = 0; i < len; i++) {
            if (!smallChar && password.charAt(i) >= 'a' && password.charAt(i) <= 'z') {
                smallChar = true;
            }
            if (!bigChar && password.charAt(i) >= 'A' && password.charAt(i) <= 'Z') {
                bigChar = true;
            }
            if (!numChar && password.charAt(i) >= '0' && password.charAt(i) <= '9') {
                numChar = true;
            }
            if (specStr.contains(password.charAt(i) + "")) {
                specChar = true;
            }
            if (i > 0 && password.charAt(i) == password.charAt(i-1)) {
                diffChar = false;
            }
        }

        return smallChar && bigChar && numChar && specChar && diffChar;
    }
}
